package com.congwulin.wechat.util;

import com.congwulin.wechat.util.exception.BusinessException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class ExceptionUtils {
    private static Logger log = LoggerFactory.getLogger(ExceptionUtils.class);

    private ExceptionUtils() {
        // 缺省构造方法
    }

    /**
     * 抛出业务异常
     *
     * @param message 异常信息
     */
    public static void wrapBusinessException(String message) {
        log.error(message);
        BusinessException ex = new BusinessException(message);
        throw ex;
    }

    /**
     * 将异常装载到快速异常通道中向上传递
     *
     * @param ex 要装载的异常
     */
    public static void wrapException(Throwable ex) {
        log.error(ex.getMessage(),ex);

        if (ex instanceof RuntimeException) {
            throw (RuntimeException) ex;
        }
        throw new RuntimeException(ex);
    }
}
